<template>
    <div id="app">
        <div class="background-wrapper" :style="backgroundStyle"></div>
        <div class="app-container" :class="{ 'white-background': shouldShowWhiteBackground }">
            <SkeletonHome v-if="loading && $route.name === 'Home'" class="fullscreen-skeleton" />
            <template v-else>
                <!-- 只有在首页（Map组件）时才显示标题 -->
                <h2 v-if="$route.name === 'Home'" style="text-align: center; margin-bottom: 5px;">上海市地图可视化</h2>
                <router-view></router-view>
            </template>
        </div>
    </div>
</template>

<script setup lang="ts">
import SkeletonHome from './components/Optimization/Skeleton.vue';
import { ref, onMounted, computed } from 'vue';
import { useRoute } from 'vue-router';
import backgroundImg from './assets/shanghai-6579053_1920.jpg'; // 根据实际路径调整

const loading = ref(true);
const route = useRoute();

onMounted(() => {
    // 模拟初始加载时间
    setTimeout(() => {
        loading.value = false;
    }, 2000);
});

const shouldShowWhiteBackground = computed(() => {
    // 在以下情况下显示白色背景：
    // 1. 不在首页
    // 2. 在首页但显示LeafletMap详细地图
    return route.name !== 'Home' ||
        (route.name === 'Home' && route.query.map === 'LeafletMap');
});

const backgroundStyle = computed(() => {
    // 只在首页且显示上海地图时显示背景图片
    if (route.name === 'Home' && !shouldShowWhiteBackground.value) {
        return {
            backgroundImage: `url(${backgroundImg})`,
            backgroundSize: 'cover',
            backgroundAttachment: 'fixed',
            backgroundPosition: 'center',
            backgroundRepeat: 'no-repeat',
            width: '100%',
            minHeight: '100vh'
        };
    }
    // 其他情况不显示背景图片
    return {
        width: '100%',
        minHeight: '100vh'
    };
});
</script>

<style scoped lang="scss">
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    text-align: center;
    color: #2c3e50;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2px;
    box-sizing: border-box;
    margin-bottom: 2px;
}

.background-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    z-index: -1;
}

.app-container {
    width: 100%;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

.white-background {
    background-color: white;
}

.fullscreen-skeleton {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background-color: #f8f9fa;
}
</style>